<template>
    <div class="container">
      <div class="form-container sign-up-container" :class="{ 'active': activePanel === 'signUp' }">
        <div class="form">
          <h2>注册</h2>
          <input type="text" v-model="username" placeholder="用户名...">
          <input type="email" v-model="email" placeholder="邮箱...">
          <input type="password" v-model="password" placeholder="密码...">
          <button @click="signUp">注册</button>
        </div>
      </div>
  
      <div class="form-container sign-in-container" :class="{ 'active': activePanel === 'signIn' }">
        <div class="form">
          <h2>商家登录/注册</h2>
          <input type="email" v-model="useraccount" placeholder="账号...">
          <input type="password" v-model="password" placeholder="密码...">
          <a href="#" class="forget-password" @click="yhdl">用户登录</a>
          <a href="#" class="forget-password" @click="glydl">管理员登陆</a>
          <button @click="signIn">登录/注册</button>
        </div>
      </div>
  
      <div class="overlay_container">
        <div class="overlay">
          <div class="overlay_panel overlay_left_container"
            :class="{ 'overlay_right_container': activePanel === 'signUp' }">
            <h2>欢迎回来！</h2>
            <p>请使用您的个人信息登录以保持联系</p>
            <button @click="showSignInPanel">登录</button>
          </div>
          <div class="overlay_panel overlay_right_container"
            :class="{ 'overlay_right_container': activePanel === 'signIn' }">
            <h2>你好，朋友！</h2>
            <p>输入您的个人信息，开始与我们一起的旅程</p>
          </div>
        </div>
      </div>
    </div>
  </template>
    
  <script>
  import axios from 'axios';
  export default {
    data() {
      return {
        activePanel: 'signIn',
        username: '',
        useraccount: '',
        password: '',
        userid: '',
        email:'',
      };
    },
    methods: {
        yhdl() {
            this.$router.push('/');
        },
        glydl() {
            this.$router.push('/glydl');
        },
      signUp() {
        // Implement your sign-up logic here
        
      },
      signIn() {
        var bool = false
      // Implement your sign-in logic here
      axios.get('http://localhost:8081/dlzc/sjdl/' + this.useraccount + '/' + this.password)
        .then(response => {
          console.log('响应数据：', response.data);

          // 确认响应数据中是否只有一个用户对象
          if (response.data.length === 1) {
            this.user = response.data[0];
            this.userid = this.user.id
            bool = true
            new Promise(resolve => setTimeout(resolve, 300)).then(() => {
              this.$router.push({ name: 'merchant', params: { id: this.userid } });

            });
          } else {
            console.error('未返回用户或返回了多个用户');

          }
        })
        .catch(error => {
          console.error('发生错误：', error);
        });
      new Promise(resolve => setTimeout(resolve, 600)).then(() => {
        if (!bool) {
          this.$notify({
            title: '失败',
            message: '登录/注册失败，请检查账号密码...',
            type: 'error'
          });
        }
      });
      },
      showSignUpPanel() {
        this.activePanel = 'signUp';
      },
      showSignInPanel() {
        this.activePanel = 'signIn';
      }
    }
  };
  </script>
  
  <style scoped>
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f6f5f7;
  }
  
  h2 {
    margin-bottom: 10px;
    font-size: 32px;
    text-transform: capitalize;
  }
  
  .container {
    position: relative;
    width: 768px;
    height: 480px;
    background-color: white;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    overflow: hidden;
    left: 50%;
    top: 50%;
    transform: translate(-50%,50%);
  }
  
  
  .form-container {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: white;
    transition: all 0.6s ease-in-out;
  }
  
  .form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    padding: 0 50px;
  }
  
  input {
    width: 100%;
    margin: 8px 0;
    padding: 12px;
    background-color: #eee;
    border: none;
  }
  
  .forget-password {
    display: inline-block;
    height: 20px;
    text-decoration: none;
    color: #bbb;
    text-transform: capitalize;
    font-size: 12px;
  }
  
  .forget-password:hover {
    color: lightslategray;
    border-bottom: 2px solid #ff4b2b;
  }
  
  button {
    background: #ff4b2b;
    padding: 10px 50px;
    border: 1px solid transparent;
    border-radius: 20px;
    text-transform: uppercase;
    color: white;
    margin-top: 10px;
    outline: none;
    transition: transform 80;
  }
  
  button:active {
    transform: scale(0.95);
  }
  
  .overlay_container {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    z-index: 100;
    right: 0;
    overflow: hidden;
    transition: all 0.6s ease-in-out;
  }
  
  .overlay {
    position: absolute;
    width: 200%;
    height: 100%;
    left: -100%;
    background-color: #ff4b2b;
  }
  
  .overlay_panel {
    position: absolute;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 50%;
    height: 100%;
    color: white;
    padding: 0 40px;
    text-align: center;
  }
  
  .overlay_panel button {
    background-color: transparent;
    border: 1px solid white;
  }
  
  .overlay_panel p {
    font-size: 12px;
    margin: 10px 0 15px 0;
  }
  
  .overlay_right_container {
    right: 0;
  }
  
  .container.active .sign-up-container {
    transform: translateX(100%);
    z-index: 5;
  }
  
  .container.active .sign-in-container {
    transform: translateX(100%);
  }
  
  .container.active .overlay_container {
    transform: translateX(-100%);
  }
  
  .container.active .overlay {
    transform: translateX(50%);
  }
  
  
  
  /* 容器样式 */
  .container {
    position: relative;
    width: 768px;
    height: 480px;
    background-color: white;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    overflow: hidden;
  }
  
  /* 左侧注册表单样式 */
  .sign-up-container {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: #ff4b2b;
    /* 橙色 */
    transition: all 0.6s ease-in-out;
  }
  
  /* 右侧登录表单样式 */
  .sign-in-container {
    position: absolute;
    top: 0;
    width: 50%;
    height: 100%;
    background-color: white;
    /* 白色 */
    transition: all 0.6s ease-in-out;
  }
  body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-image: linear-gradient(to right, #ff4b2b 50%, #fff 50%);
    /* 用渐变设置两半背景色 */
  }
  </style>
  